<?php

use yii\db\Migration;

class m170911_054551_create_mechanic_subsidy extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%mechanic_subsidy}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'mechanic_id' => $this->smallInteger()->defaultValue(0).' COMMENT \'机构id\'',
                'class_id' => $this->integer()->defaultValue(0).' COMMENT \'班级id\'',
                'lesson' => $this->smallInteger(4)->defaultValue(0).' COMMENT \'课次\'',
                'status' => $this->smallInteger(1)->defaultValue(0).' COMMENT \'0 未结算 1 已结算\'',
                'settlement_time' => $this->integer()->defaultValue(0).' COMMENT \'结算时间\'',
                'class_date' => $this->integer()->defaultValue(0).' COMMENT \'上课时间\'',
                'people_number' => $this->smallInteger()->defaultValue(0).' COMMENT \'学生数量\'',
                'amount' => $this->decimal(10,2)->defaultValue(0).' COMMENT \'补贴金额/分成金额\'',
                'lesson_amount' => $this->decimal(10,2)->defaultValue(0).' COMMENT \'单课次金额/分成金额\'',
                'goods_id' => $this->integer()->defaultValue(0).' COMMENT \'课程id\'',
                'type' => $this->smallInteger(2)->defaultValue(0).' COMMENT \'1、按学生 2、按课程\'',
                'created_at' => $this->integer()->defaultValue(0).' COMMENT \'插入时间\'',
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach($dbs as $v){
            $this->db = $v;
            $this->dropTable('{{%mechanic_subsidy}}');
        }
    }
}
